#pragma once 

#include<iostream>
#include<pthread.h>
#include<semaphore.h>
#include<vector>
#include<unistd.h>
class Task
{
  public:
    int x;
    int y;
  public:
    Task(int _x = 1,int _y = 10)
      
      :x(_x)
      ,y(_y)
    {}
    int run()
    {
      return x+y;
    }
    ~Task(){}
};
template<class T>
class RunQueue
{
  private:
    std::vector<T> v;
    int c_index;
    int p_index;
    int cap;
    sem_t block_sem;
    sem_t data_sem;
  public:
    RunQueue(int _cap = 6)
      :cap(_cap)
      ,c_index(0)
      ,p_index(0)
    {
      sem_init(&block_sem,0,cap);
      sem_init(&data_sem,0,0);
      v.resize(10);
    }
   void Push( T& data)
   {
     sem_wait(&block_sem);
     v[p_index] = data;
     p_index++;
     p_index %= cap;
     sem_post(&data_sem);
   }
   void Pop(T& data)
   {
      sem_wait(&data_sem);
      data = v[c_index];
      c_index++;
      c_index %= cap;
      sem_post(&block_sem);
   }
   ~RunQueue()
   {
     sem_destroy(&block_sem);
     sem_destroy(&data_sem);
   }

    
};
